package com.yan.demo.demo5;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;

public class Demo5 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        list.add(new Student("it001" , "黄渤" , "男" , 20 , 1.72));
        list.add(new Student("it002" , "孙红雷" , "男" , 22 , 1.78));
        list.add(new Student("it003" , "章子怡" , "女" , 18 , 1.64));
        System.out.println("打印所有学员:");
        printAll(list);
        System.out.println("身高最高的是:");
        findMaxHeight(list);
    }

    public static void printAll(ArrayList<Student>list){
        Iterator<Student> iterator = list.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }

    public static void findMaxHeight(ArrayList<Student>list){
        Double max = list.get(0).getHigh();
        Integer index = 0;
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getHigh() > max){
                max = list.get(i).getHigh();
                index = i;
            }
        }
        System.out.println(list.get(index));
    }
}
